package com.atguigu.edu.realtime.publisher.mapping;

import com.atguigu.edu.realtime.publisher.bean.UserPageCt;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

@Mapper
public interface UserUserActionMapper {
    @Select("select sum(back_ct) from dws_user_user_login_window where toYYYYMMDD(stt)=#{date}")
    BigDecimal selectBackUser(Integer date);

    @Select("select sum(uu_ct) from dws_user_user_login_window where toYYYYMMDD(stt)=#{date}")
    BigDecimal selectActiveUser(Integer date);

    @Select("select sum(register_ct) from dws_user_user_register_window where toYYYYMMDD(stt)=#{date}")
    BigDecimal selectNewUser(Integer date);

    @Select("  select 'home' page_id, sum(home_uv_ct) uv_ct\n" +
            "  from \n" +
            "  dws_traffic_home_detail_page_view_window\n" +
            "  where toYYYYMMDD(stt)=#{date}\n" +
            "  union all\n" +
            "  select 'detail' page_id, sum(detail_uv_ct) uv_ct\n" +
            "  from \n" +
            "  dws_traffic_home_detail_page_view_window\n" +
            "  where toYYYYMMDD(stt)=#{date}\n" +
            "  union all\n" +
            "  select 'cart' page_id, sum(cart_add_uu_ct) uv_ct\n" +
            "  from \n" +
            "  dws_trade_cart_add_uu_window\n" +
            "  where toYYYYMMDD(stt)=#{date}\n" +
            "  union all\n" +
            "  select 'order' page_id, sum(order_unique_user_count) uv_ct\n" +
            "  from \n" +
            "  dws_trade_order_window\n" +
            "  where toYYYYMMDD(stt)=#{date}\n" +
            "  union all\n" +
            "  select 'payment' page_id, sum(payment_suc_unique_user_count) uv_ct\n" +
            "  from\n" +
            "  dws_trade_payment_suc_window\n" +
            "  where toYYYYMMDD(stt)=#{date}")
    List<UserPageCt> selectUvByPage(Integer date);
}
